package com.amado.util;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @Author limingcheng
 * @Description 分布式唯一ID
 * @Date 2018-11-26 14:58
 * @Version v1.0
 **/
public class IdWorkerTest {
    public static void main(String[] args) {
        test(1333241872921575424L);
        test(1333241999430172672L);

    }
    public  static void test(Long idwork) {
        String s = Long.toBinaryString(idwork);
//        int amount = 64-s.length()+1;
        int seq = s.length() - 12;
        int workId = s.length() - 12 - 5;
        int centerId = s.length() - 12 - 5 - 5;
//        int time = s.length()-12-5-5-41+amount;
        int time = 0;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(s.substring(seq, s.length()));
        System.out.println(s.substring(workId, seq) + "   " + Long.parseLong(s.substring(workId, seq), 2));
        System.out.println(s.substring(centerId, workId) + "   " + Long.parseLong(s.substring(centerId, workId), 2));
        System.out.println(s.substring(time, centerId) + "   " + Long.parseLong(s.substring(time, centerId), 2) + "   " +
                (Long.parseLong(s.substring(time, centerId), 2) + 1288834974657L) + "  " + format.format(new Date((Long.parseLong(s.substring(time, centerId), 2) + 1288834974657L))));
    }

}
